<template>
  <div>
    <!-- 顶部标签 -->
    <van-nav-bar
      title="分类"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      fixed="ture"
      placeholder="ture"
    >
      <template #right>
        <van-cell  @click="showPopup">
          <van-icon name="search" size="22" />
        </van-cell>
        <van-popup v-model="show" position="top">
          <van-search
            class="search"
            v-model="value"
            placeholder="请输入你想搜索的产品"
            input-align="center"
            shape="round"
          />
        </van-popup>
      </template>
    </van-nav-bar>
    <!-- 分类选择 -->
    <van-tree-select
      height="85vh"
      :items="items"
      :main-active-index.sync="active"
    >
      <template #content>
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <van-cell v-for="(n, inx) in list" :key="inx">
            <van-card
              price="2.00"
              desc="商品描述"
              title="商品名称"
              thumb="https://img01.yzcdn.cn/vant/ipad.jpeg"
              origin-price="10.00"
            />
          </van-cell>
        </van-list>
      </template>
    </van-tree-select>
    <!-- foot -->
    <footer_bar></footer_bar>
  </div>
</template>

<script>
import footer_bar from "./footer_bar.vue";
export default {
  name: "category",
  data() {
    return {
      show: false,
      value: "",
      active: 0,
      items: [
        { text: "分组 1" },
        { text: "分组 2" },
        { text: "分组 3" },
        { text: "分组 4" },
      ],
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onClickLeft() {
      //   返回首页
      this.$router.push("/");
    },
    showPopup() {
      this.show = true;
    },
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.list.length >= 25) {
          this.finished = true;
        }
      }, 1000);
    },
  },
  components: { footer_bar },
};
</script>